package com.action;

import java.io.File;

import javax.servlet.ServletContext;

import org.apache.struts2.util.ServletContextAware;

import com.man.BookCtrl;
import com.util.DoString;

public class AdminBookUpdateAction implements ServletContextAware {
	private int		bookId;
	private String 	title;
	private String	author;
	private int		typeId;
	private String	publisher;
	private	String	publishTime;
	private String	isbn;
	private double	price;
	private int		totalAmount;
	private int 	remainder;
	private File	picturePath;
	private String	picturePathFileName;
	private String 	picturePathContentType;
	private String	content;
	private ServletContext servletContext;
	
	public int getRemainder() {
		return remainder;
	}
	public void setRemainder(int remainder) {
		this.remainder = remainder;
	}
	public int getBookId() {
		return bookId;
	}
	public void setBookId(int bookId) {
		this.bookId = bookId;
	}
	public String getPicturePathFileName() {
		return picturePathFileName;
	}
	public void setPicturePathFileName(String picturePathFileName) {
		this.picturePathFileName = picturePathFileName;
	}
	public String getPicturePathContentType() {
		return picturePathContentType;
	}
	public void setPicturePathContentType(String picturePathContentType) {
		this.picturePathContentType = picturePathContentType;
	}
	public void setServletContext(ServletContext context) {
		// TODO Auto-generated method stub
		servletContext=context;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public int getTypeId() {
		return typeId;
	}
	public void setTypeId(int typeId) {
		this.typeId = typeId;
	}
	public String getPublisher() {
		return publisher;
	}
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	public String getPublishTime() {
		return publishTime;
	}
	public void setPublishTime(String publishTime) {
		this.publishTime = publishTime;
	}
	public String getIsbn() {
		return isbn;
	}
	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public int getTotalAmount() {
		return totalAmount;
	}
	public void setTotalAmount(int totalAmount) {
		this.totalAmount = totalAmount;
	}
	public File getPicturePath() {
		return picturePath;
	}
	public void setPicturePath(File picturePath) {
		this.picturePath = picturePath;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String execute() {
		boolean isPictureUpdate=false;
		if(picturePathFileName!=null&&picturePathFileName!=""){
			isPictureUpdate=true;
			picturePath.renameTo(new File(servletContext.getRealPath("/img"), picturePathFileName));
		}
		BookCtrl bookCtrl=new BookCtrl();
		bookCtrl.updateItem(bookId,title, author, typeId, publisher, DoString.stringToDate(publishTime),
					content, isPictureUpdate?"img/"+picturePathFileName:null, isbn, price, totalAmount, remainder);
		bookCtrl.close();
		return "success";
	}	
}
